package com.hengtiansoft.lfy.widget;

import android.content.Context;
import android.graphics.drawable.AnimationDrawable;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;

import com.hengtiansoft.lfy.R;

/**
 * Created by daiye on 2016/10/26 0026.
 */

public class LoadingView extends RelativeLayout implements View.OnClickListener {

    private AnimationDrawable animationDrawable;
    private ProgressBar loading_progress;
    private LinearLayout error_layout;
    //	private TextView txt_error;
    private LinearLayout empty_layout;
    private View v;

//	RequestWebListener l;
//	public RequestWebListener getL() {
//		return l;
//	}
//	public void setL(RequestWebListener l) {
//		this.l = l;
//	}

    public LoadingView(Context context) {
        super(context);
        init(context);
    }

    public LoadingView(Context context, AttributeSet attributeset) {
        super(context, attributeset);
        init(context);
    }

    private void init(Context context) {
        v = View.inflate(context, R.layout.layout_loading, this);

        loading_progress = ((ProgressBar) v.findViewById(R.id.progressBar1));//杯子图案， 加载数据

        showLoading();
    }

    private void showLoading() {
        loading_progress.setVisibility(View.VISIBLE);
//		loading_img.post(new Runnable1(this));
    }

    private void hiddenLoading() {
        loading_progress.setVisibility(View.GONE);
//		loading_img.post(new Runnable2(this));
    }

    public static final int interfaceerror = 1;
    public static final int network_error = 2;
    public static final int showloading = 3;
    public static final int success = 4;

    public void postHandle(int state) {
        switch (state) {
            case 1:
                hiddenLoading();
                error_layout.setVisibility(View.GONE);
                empty_layout.setVisibility(View.VISIBLE);
                break;
            case 2:
                hiddenLoading();
                error_layout.setVisibility(View.VISIBLE);
                empty_layout.setVisibility(View.GONE);
                break;
            case 3:
                showLoading();
                error_layout.setVisibility(View.GONE);
                empty_layout.setVisibility(View.GONE);
                break;
            case 4:
                hiddenLoading();
                error_layout.setVisibility(View.GONE);
                empty_layout.setVisibility(View.GONE);
                break;
            default:
                break;
        }
    }

//	class Runnable1 implements Runnable {
//		Runnable1(LoadingView paramLoadingView) {
//		}
//
//		public void run() {
//			try {
//				if (animationDrawable.isRunning()) {
//					animationDrawable.stop();
//				}
//				animationDrawable.start();
//				return;
//			} catch (Exception localException) {
//			}
//		}
//	}
//
//	class Runnable2 implements Runnable {
//		Runnable2(LoadingView paramLoadingView) {
//		}
//
//		public void run() {
//			try {
//				animationDrawable.stop();
//				return;
//			} catch (Exception localException) {
//			}
//		}
//	}

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            default:
                break;
        }
    }
}